<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数字雨效果</title>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        html {
            width: 100%;
            height: 100%;
        }

        body {
            font: 15px "Microsoft YaHei", Arial, Helvetica, sans-serif;
            background-image: linear-gradient(#0ac2f3, #e4f3f6);
            color: #000;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>

<body>

    <div id="snow"></div>
    <script>
        console.log(document.documentElement.clientWidth);
        console.log((Math.ceil(Math.random() * 10)) / 10);
        function Obj() { }
        Obj.prototype.draw = function (o) {
            let speed = 0
            let startPosLeft = Math.ceil(Math.random() * document.documentElement.clientWidth)
            o.style.opacity = (Math.ceil(Math.random() * 10)) / 10
            o.style.left = startPosLeft + 'px'
            o.style.color = "#fff"
            o.style.fontSize = 12 + Math.ceil(Math.random() * 14) + 'px'
            setInterval(function () {
                if (speed < document.documentElement.clientHeight) {
                    o.style.top = speed + 'px'
                    o.style.left = startPosLeft
                    speed += 1
                } else {
                    o.remove()
                }
            })
        }

        const snow = document.querySelector('#snow')
        let arr = []
        setInterval(function () {
            const odiv = document.createElement('div')
            odiv.innerHTML = Math.ceil(Math.random() * 10)
            odiv.style.position = 'absolute'
            snow.appendChild(odiv)
            const obj = new Obj()
            obj.draw(odiv)
        }, 100)


        // console.log(odiv);

        // setInterval(function () {
        //     console.log(odiv.offsetTop);
        //     if (odiv.offsetTop > document.documentElement.clientHeight) {
        //         odiv.remove()
        //     }
        // })
    </script>
</body>

</html>